import Vue from 'vue';

class PageEventBus {
  constructor(bus) {
    this.bus = bus;
  }

  emit(pageComponent, event, ...args) {
    args = pageComponent ? [pageComponent.$pageOptions].concat(args) : args;
    this.bus.$emit(event, ...args);
  }

  on(event, callback) {
    this.bus.$on(event, (...args) => {
      callback(...args);
    });
  }
}

const eventBus = new Vue();
Vue.prototype.$eventBus = eventBus;
Vue.prototype.$pageEventBus = new PageEventBus(eventBus);
